package com.projectdemo.springbootdemo1.service;

import com.projectdemo.springbootdemo1.dao.EmployeeRepository;
import com.projectdemo.springbootdemo1.mapper.EmployeeMapper;
import com.projectdemo.springbootdemo1.pojo.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;

@Service
public class EmployeeService {

    @Autowired
    private EmployeeRepository employeeRepository;

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Autowired
    private EmployeeMapper employeeMapper;

    public Iterable<Employee> getAllEmployees() {
//        return employeeRepository.findAll();
        return employeeMapper.findAll();
    }

    public Employee getEmployeeById(Integer id) {
        return employeeRepository.findById(id).orElse(null);
    }

    public Employee saveEmployee(Employee user) {
        return employeeRepository.save(user);
    }

    public void deleteEmployee(Integer id) {
        jdbcTemplate.update("DELETE FROM EMPLOYEE WHERE ID = ?", new Object[]{id});
//        employeeRepository.deleteById(id);
    }
}
